<%--
  Created by IntelliJ IDEA.
  User: cxy
  Date: 2018-05-31
  Time: 16:02
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>添加药品</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/statics/bootstrap/css/bootstrap.css" />
    <link rel="stylesheet" href="${pageContext.request.contextPath}/statics/table/bootstrap-table.min.css" />
    <link rel="stylesheet" href="${pageContext.request.contextPath}/statics/date/bootstrap-datetimepicker.min.css" />
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/statics/hplus/css/plugins/sweetalert/sweetalert.css" />
    <script type="text/javascript" src="${pageContext.request.contextPath}/statics/jquery-3.2.1.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/statics/bootstrap/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/statics/table/bootstrap-table.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/statics/table/locale/bootstrap-table-zh-CN.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/statics/date/Moment.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/statics/date/bootstrap-datetimepicker.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/statics/hplus/js/plugins/sweetalert/sweetalert.min.js"></script>
</head>
<body>
<div class="modal fade" id="add" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">添加药品</h4>
            </div>
            <div class="modal-body">
                <form>
                    <input  type="hidden" id="id" name="id" />
                    <div class="form-group">
                        <label for="MName">药品名称：</label>
                        <input type="text" class="form-control" id="MName">
                    </div>
                    <div class="form-group">
                        <label for="spec">药品规格：</label>
                        <input type="text" class="form-control" id="spec">

                    </div>
                    <div class="form-group">
                        <label for="Nbumber">药品数量：</label>
                        <input type="text" class="form-control" id="Nbumber"/>
                    </div>
                    <div class="form-group">
                        <label for="Dosageform">药品剂型x1：</label>
                        <input type="text" class="form-control" id="Dosageform"/>
                            <%--<option value="1">迷你包</option>
                            <option value="2">小包</option>
                            <option value="3">中包</option>
                            <option value="4">大包</option>
                            <option value="5">豪华包</option>
                            <option value="6">VIP包</option>--%>
                        </select>
                    </div>
                    <div class="form-group">
                        <label for="Termofvalidity">药品有效期：</label>
                        <input type="text" class="form-control" id="Termofvalidity"/>
                            <%--<option value="1">迷你包</option>
                            <option value="2">小包</option>
                            <option value="3">中包</option>
                            <option value="4">大包</option>
                            <option value="5">豪华包</option>
                            <option value="6">VIP包</option>--%>
                        </select>
                    </div>

                </form>
            </div>
            <div class="modal-footer">
                <button class="btn btn-default" data-dismiss="modal">关闭</button>
                <button onclick="add()" class="btn btn-primary">提交</button>
            </div>
        </div>
    </div>
</div>

</body>
<script type="text/javascript">
    $(function () {
        $("#add").modal("show");
        $.ajax({
            "url":"${pageContext.request.contextPath}/medicine/select",
            "type":"post",
            "datatype":"json",
            "success":function(data){
                $("#typeid1").empty();
                for(var i=0;i<data.length;i++){
                    $("#typeid").append("<option value='"+data[i].id+"' >"+data[i].typename+"</option>");
                }

            }
        });

    });

    function add() {
        var nName = $("#MName").val();
        var spec = $("#spec").val();
        var nbumber = $("#Nbumber").val();
        var dosageform = $("#Dosageform").val();
        var termofvalidity = $("#Termofvalidity").val();

        //send ajax
        $.ajax({
            url: "${pageContext.request.contextPath}/medicine/addMedicine",
            data: {"MName": nName, "Spec": spec, "Nbumber": nbumber, "Dosageform": dosageform,"Termofvalidity":termofvalidity},
            type: "post",
            ContentType:"application/json",
            dataType: "text",
            success: function (data) {
                alert("添加成功");
                var r = eval("(" + data + ")");
                //绑定到table上
                $("#dg").bootstrapTable('load', r);
                location = "Medicine.jsp";
                //关闭对话框
                $('#add').modal('hide');
            },
            error:function () {
                alert("添加失败");
            }
        })
    }
</script>
</html>
